package io.terminus.paas.profiler.dubbo.filter

import com.alibaba.dubbo.common.Constants
import com.alibaba.dubbo.common.extension.Activate
import com.alibaba.dubbo.rpc.*

/**
 * Created by gengrong on 16/4/7.
 */
@Activate(group = arrayOf(Constants.CONSUMER), order = -10001)
class ConsumerAfterFilter : Filter {

    override fun invoke(invoker: Invoker<*>, invocation: Invocation): Result {
        val attachments = mutableMapOf<String, String>()
        attachments.putAll(RpcContext.getContext().attachments)
        try {
            return invoker.invoke(invocation)
        } finally {
            RpcContext.getContext().attachments.putAll(attachments)
        }
    }

}